from pytube import YouTube

while True:
    # Prompt the user to enter the video URl
    video_url = input("Enter the video URL: ")
    # check if the URL starts with "https://'
    if video_url.startswith("https://"):
        try:
            # create a YouTube object with the URL
            yt = YouTube(video_url)
            # get the video title
            video_title = yt.title
            stream = yt.streams.get_highest_resolution()
            # download the video
            stream.download()
            print(f"Downloaded {video_title} successfully!")

            break

        except Exception as e:
            print(f"Error downloading {video_url}: {e}")
    else:
        print("Invalid URL. Please enter a valid YouTube video URL.")

# print a final message
print("Exiting...!")
